package com.kyzh.core.pager.me.settings

import android.os.Bundle
import android.util.Log
import android.view.View
import androidx.core.content.ContextCompat
import androidx.databinding.DataBindingUtil
import com.gushenge.core.base.Base
import com.gushenge.core.dao.GlobalConsts
import com.gushenge.core.dao.GlobalKeys
import com.gushenge.core.dao.MMKVConsts
import com.gushenge.core.dao.MMKVConsts.uid
import com.kyzh.core.R
import com.gushenge.core.base.activity.BaseActivity
import com.kyzh.core.activities.BrowserActivity
import com.kyzh.core.databinding.ActivitySettingsv3Binding
import com.kyzh.core.databinding.ItemSettingsV3Binding
import com.kyzh.core.pager.me.about.AboutActivity
import com.kyzh.core.utils.*

class SettingsV3Activity : BaseActivity() {
    private lateinit var binding:ActivitySettingsv3Binding
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = DataBindingUtil.setContentView(this,R.layout.activity_settingsv3)

        Log.e("initView111: ", MMKVConsts.languageConfig )
        initView()
    }

    private fun initView() {
        UpdateApp().updateMain(this){

        }
        binding.apply {
            vStandard.setInfo(R.drawable.ic_settings_standard,getString(R.string.normalSetting))
            vStandard.root.setOnClickListener {
                startActivity<StandardSettingsActivity>()
            }
            vNotice.setInfo(R.drawable.ic_settings_notice,getString(R.string.noticeSetting))
            vNotice.root.setOnClickListener {
                startActivity<NoticeSettingsActivity>()
            }
            vRegister.setInfo(R.drawable.ic_settings_privacy,getString(R.string.registerAgreement))
            vRegister.root.setOnClickListener {
                startActivity<BrowserActivity>(GlobalKeys.LINK to GlobalConsts.REGISTER_PACT,GlobalKeys.TITLE to getString(R.string.registerAgreement))
            }

            vDownload.setInfo(R.drawable.ic_settings_download,getString(R.string.downloadAndInstall))
            vDownload.root.setOnClickListener {
                startActivity<DownloadSettingsActivity>()
            }
            vPact.setInfo(R.drawable.ic_settings_privacy,getString(R.string.privacyPolicy))
            vPact.root.setOnClickListener {
                startActivity<BrowserActivity>(GlobalKeys.LINK to GlobalConsts.PRIVACY_PACT,GlobalKeys.TITLE to getString(R.string.privacyPolicy))
            }
            vUpdate.setInfo(R.drawable.ic_settings_update,getString(R.string.versionUpdate))
            vUpdate.root.setOnClickListener {
                UpdateApp().update(this@SettingsV3Activity)
            }
            vAbout.setInfo(R.drawable.ic_settings_about,getString(R.string.aboutUs))
            vAbout.root.setOnClickListener {
                startActivity<AboutActivity>()
            }
            if(uid.isNotEmpty()){
                vLogoff.setInfo(R.drawable.icon_logoff,"账号注销")
                vLogoff.root.setOnClickListener {
                    startActivity<BrowserActivity>(GlobalKeys.LINK to "${Base.BASEURL}?ct=zhanwu&ac=userdelete&uid=$uid&t=$time&sign=${httpSign(uid)}",GlobalKeys.TITLE to "账号注销")
                }
            }else{
                vLogoff.root.visibility= View.GONE
            }

        }
    }

    private fun ItemSettingsV3Binding.setInfo(icon: Int, text: String) {
        this.tvStart.setCompoundDrawablesWithIntrinsicBounds(ContextCompat.getDrawable(this@SettingsV3Activity,icon),null,null,null)
        this.text = text
    }
}

